<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>canvas作为纹理</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }
  </style>
</head>
<body>
  <script>
    // canvas绘制
    const canvas = document.createElement('canvas');
    canvas.width = 512;
    canvas.height = 128;
    const ctx = canvas.getContext('2d');
    // 矩形区域背景
    ctx.fillStyle = '#ff00ff';
    ctx.fillRect(0, 0, 512, 128);
    // 文字
    ctx.beginPath();
    ctx.translate(256, 64);
    ctx.fillStyle = '#000000';
    ctx.font = 'bold 48px 宋体';
    ctx.textBaseline = 'middle';
    ctx.textAlign = 'center';
    ctx.fillText('YZH_cd', 0, 0);
    ctx.closePath();
  </script>
  <script src="./_canvasTexture.js" type="module"></script>
</body>
</html>